<template>
  <div class="container container1">
    <button @click="getMenuList" class="buttonClass">点击跳转</button>
    <iframe :src="src" width="100%" frameborder="0" scrolling="auto"></iframe>
  </div>
</template>
<script>
import common from '../../kits/common'

export default {
  name: 'commandCenter',
  data() {
    return {
      src: '',
    }
  },
  created() {
    this.src = common.commonApi + 'screen/'
  },
  methods: {
    getMenuList() {
      this.axios({
        method: 'post',
        url: '/api-m/menus/me',
        headers: {
          'Content-Type': 'application/json', //设置请求头请求格式为JSON
          Authorization: localStorage.getItem('access_token'), //设置token 其中K名要和后端协调好
        },
      }).then(
        (response) => {
          //先清除之前的选中
          //清除tab栏数据

          this.$store.state.sliderBar = []
          this.$store.state.keekAlives = []
          localStorage.removeItem('sliderBar')
          // 顶部栏的选中清空
          this.$store.state.currentItem = ''
          this.$store.state.currentSelectItem = ''

          this.canLogin = false
          // this.$store.state.menuList = response.data;
          if (response.data == '' || response.data == null) {
            this.errorMsg_QY = '该账号未分配权限'
            this.errorMsg_JC = '该账号未分配权限'
            return
          }
          // 处理返回数据，设置默认选中项
          for (var i = 0; i < response.data.appList.length; i++) {
            var item = response.data.appList[i]
            if (item.isSelected) {
              response.data.appList.splice(i, 1)
              response.data.appList.unshift(item)
            }
          }
          // 处理数据结束
          this.$store.state.menuList = response.data.appList[0].menuList
          var menuListTotalCon = []
          for (var i = 0; i < response.data.appList.length; i++) {
            var item = response.data.appList[i]
            menuListTotalCon.push(response.data.appList[i].menuList)
          }

          var menuListTotal = []
          for (var i = 0; i < menuListTotalCon.length; i++) {
            menuListTotal = menuListTotal.concat(menuListTotalCon[i])
          }

          this.$store.state.menuListTotal = menuListTotal

          this.$store.state.appList = response.data.appList
          this.$store.state.currentItem = ''
          // localStorage.setItem("menuList",JSON.stringify(response.data));
          localStorage.setItem('urlName', 'constructMonitorHome')
          //默认选中

          var item = response.data.appList[0]

          //默认选中
          if (item.menuList[0].child) {
            this.$router.push(item.menuList[0].child[0].url)
            this.$store.state.activeMenu = item.menuList[0].child[0].url
            //tab栏选中
            this.$store.state.sliderBar = [item.menuList[0].child[0]]
            this.$store.state.activeIndex = item.menuList[0].child[0].url
          } else {
            if (item.code == 'company') {
              localStorage.setItem('urlName', 'monitorHome')
            } else if (item.code == 'project') {
              localStorage.setItem('urlName', 'constructMonitorHome')
            }
            this.$router.push(item.menuList[0].url)
            this.$store.state.activeMenu = item.menuList[0].url

            //tab栏选中
            localStorage.removeItem('sliderBar')
          }
        },
        (response) => {
          this.isAdd = false
          this.$message.error('登录失败')
          this.canLogin = false
        }
      )
      // .catch(error => {
      //   this.$message.error('登录失败');
      // //   this.canLogin = false;
      // });
    },
  },
}
</script>
<style scoped lang="less">
.buttonClass {
  position: absolute;
  top: 0;
  width: 100px;
  height: 54px;
  z-index: 100000px;
  right: 0;
  opacity: 0;
}
.container1 {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2020;
  iframe {
    height: calc(100%);
  }
}
</style>
